<template>
	<view class="equipment"
		style="background: url(/static/imgbgc.png) no-repeat; background-size: 100% 100%;height: 100%;">>
		<view class="main">
			<view class="equipment-navbar">
				<view class="" style="height: 50rpx;"></view>
				<view class="equipment-add">
					<view class="">
						<u-tabs :list="list1" @click="handleTabs" :inactiveStyle="{
				    color: '#fff',
				    transform: 'scale(1)'
				}" lineColor="#fff" :activeStyle="{
				    color: '#fff',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'}"></u-tabs>
					</view>
					<view class="right" v-if="activeTab == 0">
						<view class="add-btn" @tap="isAdd=!isAdd">
							{{$t('equipment.name1')}}
						</view>
						<view class="mask" v-show="isAdd" @tap="isAdd=false">
							<view class="position-add">
								<view class="item-add" @tap="handleScanCode">
									{{$t('equipment.name2')}}
								</view>
								<view class="item-add" @tap="handleAdd">
									{{$t('equipment.name1')}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<scroll-view scroll-y="true" style="height: 85vh;padding-bottom: 100rpx;">
				<view class="equipment-main">
					<view class="equipment_box">
						<view class="equipment_list">
							<view v-for="(item,index) in list" :key="index">
								<view class="equipmentItem">
									<view class="equipment_item black" @click="handleModal(item)">
										<view class="l">
											<image :src="$fun.imgUrl(item.image)" mode=""></image>
											<view class="center_info">
												<view class="text1">
													{{item.desc ? item.desc :''}}
												</view>
												<view class="text2">
													{{item.addrIspCode}}
												</view>

												<view class="text">
													<view class="info">
														{{item.rn}}
													</view>
												</view>
												<view class="text2" style="color: #999;margin-top: 5rpx;">
													{{$fun.formatTime(item.createtime * 1000)}}
												</view>
												<view class="" style="margin-top: 5rpx;"
													:style="{color:+item.status ? '#2ac507':'#f32c04'}">
													{{+item.status ? $t('equipment.name3'):$t('equipment.name4')}}
												</view>
											</view>
										</view>
										<view class="r">
											<view class="info">
												<text
													style="color: #fff;font-size: 38rpx;font-weight: 400;">{{item.income}}</text>
												<text>{{$t('equipment.name5')}}</text>
												<view class="flex"
													@click="jump(`/pageC/equipmentDetail?name=${item.sn}&name1=${item.rn}&onlineCode=${item.onlineCode}`)">
													<view class="detail">{{$t('equipment.name6')}}</view>
													<image src="/static/newProject/equipment/icon_r.png" mode="">
													</image>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<noneDate v-if="!list.length" />
			</scroll-view>
			<u-modal :show="show" :title="$t('equipment.name7')" @confirm="handleConfirm">
				<view class="" slot="default">
					<textarea v-model="equActive.code" placeholder-class="textareaPlace" :placeholder="$t('equipment.name8')"
						style="height: 150rpx;"></textarea>
				</view>
			</u-modal>
		</view>
		<TabBar :tabBarShow="1"></TabBar>
	</view>
</template>

<script>
	import noneDate from '@/components/noneDate/noneDate.vue'
	import headerTop from "@/components/dacizi-headtag/dacizi-headtag.vue"
	export default {
		components: {
			headerTop,
			noneDate
		},
		data() {
			return {
				show: false,
				list1: [{
						name: this.$t('equipment.name9'),
					},
					// {
					// 	name: '汇拨',
					// },
				],
				equipmentInfo: {
					count: 0
				},
				list: [],
				page: 1,
				limit: 20,
				activeIndex: 0,
				group_id: -1,
				pipeType: '',
				GroupList: [],
				GroupType: [],
				count: 0,
				activeTab: 0,
				isAdd: false,
				vlan: -1,
				releaseList: [],
				equActive: {
					sn: '',
					code: ''
				}
			}
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			setTimeout(() => {
				this.getGroupList()
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			if (this.page != 1) {
				this.getUserSnList(this.page, this.limit)
			}
		},
		onNavigationBarButtonTap(e) {
			this.$fun.jump('/pageC/add')
		},
		// 分享好友
		onShareAppMessage() {
			return {
				title: '云算能',
				path: JSON.parse(uni.getStorageSync('gitH5Qrcode')),
			}
		},
		// 分享朋友圈
		onShareTimeline() {
			return {
				title: '云算能',
				query: JSON.parse(uni.getStorageSync('gitH5Qrcode')),
			}
		},
		onShow() {
			this.list = []
			this.page = 1
			this.getGroupList()
		},
		onHide() {
			this.isAdd = false
		},
		methods: {
			async handleConfirm() {
				if (!this.equActive.code) return this.$fun.msg(this.$t('equipment.name8'))
				const res = await this.$fun.ajax.post('butt/activate', {
					...this.equActive
				})
				this.$fun.msg(res.msg)
				this.show = false
				this.equActive = {
					sn: '',
					code: ''
				}
				this.page = 1,
					this.limit = 20
				this.list = []
				this.getUserSnList()
			},
			handleModal(item) {
				if (!+item.status) {
					this.equActive.sn = item.sn
					this.show = true
				}
			},
			handleFilter(value) {
				this.page = 1,
					this.limit = 20
				this.list = []
				this.getUserSnList()
			},
			// 拨号信息
			handleDialResult(item) {
				this.$fun.jump(`/pageC/dialResult/dialResult?sn=${item.sn}`)
			},
			handleScanCode() {
				console.log(11);
				let _that = this
				//#ifdef H5
				this.$fun.msg(this.$t('equipment.name10'))
				//#endif
				// #ifndef H5
				uni.scanCode({
					success: function(res) {
						_that.$fun.jump(`/pageC/add?sn=${res.result}`)
					}
				});
				// #endif
			},
			handleAdd() {
				this.$fun.jump('/pageC/add')
			},
			// 拨号设置
			handleDial() {
				this.$fun.jump('/pageC/DialSetting/DialSetting')
			},
			// 点击tabs
			handleTabs(item) {
				console.log(1111, item);
				this.page = 1,
					this.limit = 20
				this.list = []
				this.releaseList = []
				this.activeTab = item.index
				if (item.index == 0) {
					// 设备
					this.pipeType = -1
					this.vlan = -1
					this.getUserSnList()
				} else if (item.index == 1) {
					// 多拨号
					this.pipeType = 3
					this.vlan = 1
					this.getUserSnList()
				} else {
					// 设备托管
					this.getReleaseList()
				}
			},
			async getReleaseList() {
				const res = await this.$fun.ajax.post('user/user_release', {
					page: this.page,
					limit: this.limit,
				})
				if (res.data.length > 0) {
					this.releaseList.push(...res.data);
					this.addressList = res.data
					this.page++
				} else {
					if (this.page != 1) {
						this.$fun.msg(this.$t('equipment.name11'))
					}
				}
			},
			getUserSnList(page, limit) {
				this.$fun.ajax.post('butt/userSnList', {
					page: this.page,
					limit: this.limit,
					onlineCode: -1,
					group_id: this.group_id,
					pipeType: -1,
					vlan: this.vlan
				}).then(res => {
					if (res.data.list.length > 0) {
						this.list.push(...res.data.list);
						this.addressList = res.data
						this.page++
					} else {
						if (this.page != 1) {
							this.$fun.msg(this.$t('equipment.name11'))
						}
					}
				})
			},
			clickItem(item, index) {
				this.activeIndex = index
				this.list = []
				this.page = 1
				this.getUserSnList(this.page, this.limit)
			},
			async getGroupList(onlineCode = -1) {
				await this.getUserSnList(this.page, this.limit)
			},
			jump(url) {
				this.$fun.jump(url)
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.equipment {
		// position: relative;
		height: 100%;

		.bgc {
			height: 100%;
		}

		.main {}

		.equipment-navbar {
			background-color: transparent;
			border-radius: 0 0 20rpx 20rpx;

			.equipment-add {
				position: relative;
				height: 100rpx;
				display: flex;
				justify-content: space-between;
				align-items: flex-end;
				padding-bottom: 15rpx;
				padding-right: 20rpx;

				.right {
					position: relative;
					font-size: 14px;
					color: #cacaca;
					padding-bottom: 20rpx;

					.mask {
						background-color: transparent;
						position: absolute;
						z-index: 999;
						top: 100%;
						left: 0;
						width: 100%;
						height: 1000rpx;

						.position-add {
							position: absolute;
							z-index: 9999;
							top: 0;
							right: 0;
							background-color: rgba(30, 30, 30, 0.8);
							width: 216rpx;
							// color: #000;
							border-radius: 10rpx;
							padding: 5rpx;
							border: 2rpx solid #4c4c4c;

							.item-add {
								padding: 20rpx 0;
								font-size: 32rpx;
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								color: #cacaca;
								text-align: center;
								display: flex;
								justify-content: center;
							}
						}
					}
				}
			}
		}

		.release {
			padding: 30rpx;

			.release-item {
				width: 100%;
				background-color: #cacaca;
				border-radius: 20rpx;
				margin-bottom: 30rpx;

				// align-items: center;
				.lt {
					width: 188rpx;
					height: 188rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.rt {
					flex: 1;
					padding: 0 30rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 30rpx;
					color: #19233C;
					line-height: 38rpx;

					.title {
						margin-top: 20rpx;
					}

					.line {
						padding: 10rpx 0 10rpx;
						font-weight: 600;

						.balance {
							color: #232323;
							font-size: 24rpx;
						}

						.amount {
							color: #19be6b;
							font-size: 24rpx;
						}
					}
				}
			}
		}

		.equipment-main {
			position: relative;
		}

		.top_equipment {
			padding-top: 20rpx;
			width: 100%;
			height: 88rpx;
			background: #2980f7;
			box-sizing: border-box;
			padding: 0 0rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.top_item {
				width: 25%;
				height: 88rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				font-family: Microsoft YaHei;
				color: #cacaca;
				font-size: 30rpx;
				// border: 1rpx solid #2b7cff;
				// border-radius: 10rpx;

				.num {
					margin-bottom: 20rpx;
					font-weight: bold;
				}

				.circular {
					position: absolute;
					top: 15rpx;
					right: 15rpx;
					width: 15rpx;
					height: 15rpx;
					border-radius: 50%;
				}
			}

			.active {
				// border-radius: 10rpx;
				background: #cacaca;
				color: #ffa136;
			}
		}

		.top_box {
			background: #cacacaFFF;
			display: flex;
			padding: 0 32rpx;
			height: 95rpx;
			align-items: center;
			justify-content: space-between;

			.l {
				display: flex;
				align-items: center;

				image {
					margin-left: 13rpx;
					margin-right: 10rpx;
					width: 33rpx;
					height: 38rpx;
				}

				text {
					font-size: 32rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #cacaca;
				}
			}

			.r {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #2980F7;

				image {
					margin-right: 10rpx;
				}
			}
		}

		.equipment_box {
			padding: 0rpx 30rpx;


			.cenetr_box {
				margin-top: 29rpx;
				height: 80rpx;
				background: #EEEEEE;
				border-radius: 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;
				// padding: 0 30rpx;
				box-sizing: border-box;

				.l {
					font-size: 20rpx;
					font-family: Microsoft YaHei;
					font-weight: bold;
					color: #cacaca;
				}

				.r {
					width: 336rpx;
					height: 80rpx;
					background: #2980F7;
					border-radius: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #cacacaFFF;

					image {
						margin-left: 90rpx;
						width: 24rpx;
						height: 14rpx;
					}
				}
			}


		}

		.equipment_list {
			margin-top: 20rpx;

			.equipmentItem {
				background-color: rgba(25, 40, 65, 0.7);
				padding: 25rpx 30rpx;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				width: 100%;
				box-sizing: border-box;

				.item-bottom {
					display: flex;
					justify-content: space-between;
					font-size: 12px;
					margin-top: 10rpx;
				}

				.item-icon {
					display: flex;
					align-items: center;

					.item-text {
						margin-left: 5rpx;
					}
				}
			}

			.equipment_item {
				display: flex;
				justify-content: space-between;

				.l {
					display: flex;

					image {
						width: 165rpx;
						height: 165rpx;
						border-radius: 10rpx;
					}

					.center_info {
						margin-left: 14rpx;
						display: flex;
						flex-direction: column;
						width: 300rpx;

						.text1 {
							font-size: 32rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #cacaca;
						}

						.text2 {
							margin-top: 20rpx;
							font-size: 24rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #fefefe;
						}

						.text {

							display: flex;
							align-items: center;

							.b {
								width: 28rpx;
								height: 8rpx;
								background: #55B953;
								border-radius: 4rpx;
							}

							.info {
								width: 277rpx; //固定宽度
								overflow: hidden; //溢出隐藏
								white-space: nowrap; //不换行
								text-overflow: ellipsis; //显示...
								font-size: 24rpx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #cacaca;
							}
						}

					}
				}

				.r {
					display: flex;
					justify-content: flex-end;
					align-items: center;

					.info {
						height: 100%;
						display: flex;
						flex-direction: column;
						justify-content: flex-start;
						text-align: right;

						text:nth-child(1) {
							margin-top: 20rpx;
							font-size: 40rpx;
							font-family: Microsoft YaHei;
							font-weight: 400;
							color: #E91A4B;
							text-align: center;
						}

						text:nth-child(2) {
							margin-top: 10rpx;
							font-size: 26rpx;
							font-family: Adobe Heiti Std;
							font-weight: normal;
							color: #cacaca;
							text-align: center;
						}

						.detail {
							font-size: 24rpx;
							font-family: Adobe Heiti Std;
							font-weight: normal;
							color: #1E84F1;
							margin: 15rpx 0;
						}

					}

					image {
						margin-left: 22rpx;
						width: 14rpx;
						height: 24rpx;
					}
				}
			}

			.gray {
				background: #F6F6F6;
				color: #CCCCCC;
			}

			.black {
				// background: #F6F6F6;
				color: #cacaca;
			}
		}

	}

	.noneDate_box {
		margin-top: 126rpx;
		text-align: center;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		image {
			width: 309rpx;
			height: 317rpx;
		}

		.button {
			margin: 30rpx 0;
			width: 200rpx;
			height: 60rpx;
			background: linear-gradient(-30deg, #FE555A 0%, #F99E35 100%);
			border-radius: 30rpx;
			font-size: 22rpx;
			font-family: Microsoft YaHei;
			color: #cacacaFFF;
			line-height: 60rpx;
			text-align: center;
		}
	}

	.dial {
		.equipment_list {
			padding: 20rpx 30rpx;

			.equipment_item {
				margin-bottom: 0;
				padding: 0;

				.l {
					image {
						width: 130rpx;
						height: 130rpx;
						border-radius: 10rpx;
					}
				}
			}
		}
	}
</style>